﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace EasyTrader.Form
{
    public partial class DashboardFrm : System.Windows.Forms.Form
    {
        // 통합 신호 관리자 생성
        EasyTrader.Signal.TotalSignalManager m_GSignalManager = null;
        public EasyTrader.Signal.TotalSignalManager GSignalManager
        {
            get { return m_GSignalManager; }
            set { m_GSignalManager = value; }
        }

        System.Windows.Forms.Timer timer = new System.Windows.Forms.Timer();
        public DashboardFrm()
        {
            InitializeComponent();
            InitTimer();
        }

        private void InitTimer()
        {
            timer.Interval = 1000;
            timer.Tick += new EventHandler(OnTimerTick);
            timer.Start();
        }

        private void OnTimerTick(object sender, EventArgs e)
        {
            UpdateProgressBars();
        }

        public void UpdateProgressBars()
        {
            if (m_GSignalManager == null || GlobalVar.AllDataDownloaded == false)
                return;

            string valueText = "";
            if (m_GSignalManager.ForeignPersonKospiSignal > 0.0)
            {
                etProgressBarForeignPerson.StartColor = Color.Red;
                etProgressBarForeignPerson.EndColor = Color.Red;
                valueText = "매수 : ";
            }
            else
            {
                etProgressBarForeignPerson.StartColor = Color.Blue;
                etProgressBarForeignPerson.EndColor = Color.Blue;
                valueText = "매도 : ";
            }

            etProgressBarForeignPerson.Value = (int)Math.Abs(m_GSignalManager.ForeignPersonKospiSignal);
            valueText += etProgressBarForeignPerson.Value.ToString();
            valueText += "%";
            etProgressBarForeignPerson.ValueText = valueText;
            //////////////////////////////////////////////////////////////////////////
            if (m_GSignalManager.OrganPersonKospiSignal > 0.0)
            {
                etProgressBarOrganPerson.StartColor = Color.Red;
                etProgressBarOrganPerson.EndColor = Color.Red;
                valueText = "매수 : ";
            }
            else
            {
                etProgressBarOrganPerson.StartColor = Color.Blue;
                etProgressBarOrganPerson.EndColor = Color.Blue;
                valueText = "매도 : ";
            }

            etProgressBarOrganPerson.Value = (int)Math.Abs(m_GSignalManager.OrganPersonKospiSignal);
            valueText += etProgressBarOrganPerson.Value.ToString();
            valueText += "%";
            etProgressBarOrganPerson.ValueText = valueText;

            //////////////////////////////////////////////////////////////////////////
            if (m_GSignalManager.FutureSignal > 0.0)
            {
                etProgressBarForeignFuture.StartColor = Color.Red;
                etProgressBarForeignFuture.EndColor = Color.Red;
                valueText = "매수 : ";
            }
            else
            {
                etProgressBarForeignFuture.StartColor = Color.Blue;
                etProgressBarForeignFuture.EndColor = Color.Blue;
                valueText = "매도 : ";
            }

            etProgressBarForeignFuture.Value = (int)Math.Abs(m_GSignalManager.FutureSignal);
            valueText += etProgressBarForeignFuture.Value.ToString();
            valueText += "%";
            etProgressBarForeignFuture.ValueText = valueText;

            //////////////////////////////////////////////////////////////////////////
            if (m_GSignalManager.OptionCallPutSignal > 0.0)
            {
                etProgressBarPersonPutCall.StartColor = Color.Red;
                etProgressBarPersonPutCall.EndColor = Color.Red;
                valueText = "매수 : ";
            }
            else
            {
                etProgressBarPersonPutCall.StartColor = Color.Blue;
                etProgressBarPersonPutCall.EndColor = Color.Blue;
                valueText = "매도 : ";
            }

            etProgressBarPersonPutCall.Value = (int)Math.Abs(m_GSignalManager.OptionCallPutSignal);
            valueText += etProgressBarPersonPutCall.Value.ToString();
            valueText += "%";
            etProgressBarPersonPutCall.ValueText = valueText;

            //////////////////////////////////////////////////////////////////////////
            if (m_GSignalManager.ProgramSignal > 0.0)
            {
                etProgressBarProgram.StartColor = Color.Red;
                etProgressBarProgram.EndColor = Color.Red;
                valueText = "매수 : ";
            }
            else
            {
                etProgressBarProgram.StartColor = Color.Blue;
                etProgressBarProgram.EndColor = Color.Blue;
                valueText = "매도 : ";
            }

            etProgressBarProgram.Value = (int)Math.Abs(m_GSignalManager.ProgramSignal);
            valueText += etProgressBarProgram.Value.ToString();
            valueText += "%";
            etProgressBarProgram.ValueText = valueText;

            //////////////////////////////////////////////////////////////////////////

            if (m_GSignalManager.BidsAsksSignal > 0.0)
            {
                etProgressBarBidsAsks.StartColor = Color.Red;
                etProgressBarBidsAsks.EndColor = Color.Red;
                valueText = "매수 : ";
            }
            else
            {
                etProgressBarBidsAsks.StartColor = Color.Blue;
                etProgressBarBidsAsks.EndColor = Color.Blue;
                valueText = "매도 : ";
            }

            etProgressBarBidsAsks.Value = (int)Math.Abs(m_GSignalManager.BidsAsksSignal);
            valueText += etProgressBarBidsAsks.Value.ToString();
            valueText += "%";
            etProgressBarBidsAsks.ValueText = valueText;

            //////////////////////////////////////////////////////////////////////////

            if (m_GSignalManager.BuySellSignal > 0.0)
            {
                etProgressBarBuySell.StartColor = Color.Red;
                etProgressBarBuySell.EndColor = Color.Red;
                valueText = "매수 : ";
            }
            else
            {
                etProgressBarBuySell.StartColor = Color.Blue;
                etProgressBarBuySell.EndColor = Color.Blue;
                valueText = "매도 : ";
            }

            etProgressBarBuySell.Value = (int)Math.Abs(m_GSignalManager.BuySellSignal);
            valueText += etProgressBarBuySell.Value.ToString();
            valueText += "%";
            etProgressBarBuySell.ValueText = valueText;

            //////////////////////////////////////////////////////////////////////////
            if (m_GSignalManager.WaveSignal > 0.0)
            {
                etProgressBarWave.StartColor = Color.Red;
                etProgressBarWave.EndColor = Color.Red;
                valueText = "매수 : ";
            }
            else
            {
                etProgressBarWave.StartColor = Color.Blue;
                etProgressBarWave.EndColor = Color.Blue;
                valueText = "매도 : ";
            }

            etProgressBarWave.Value = (int)Math.Abs(m_GSignalManager.WaveSignal);
            valueText += etProgressBarWave.Value.ToString();
            valueText += "%";
            etProgressBarWave.ValueText = valueText;

            //////////////////////////////////////////////////////////////////////////
            if (m_GSignalManager.ForeSignal > 0.0)
            {
                etProgressBarForecast.StartColor = Color.Red;
                etProgressBarForecast.EndColor = Color.Red;
                valueText = "매수 : ";
            }
            else
            {
                etProgressBarForecast.StartColor = Color.Blue;
                etProgressBarForecast.EndColor = Color.Blue;
                valueText = "매도 : ";
            }

            etProgressBarForecast.Value = (int)Math.Abs(m_GSignalManager.ForeSignal);
            valueText += etProgressBarForecast.Value.ToString();
            valueText += "%";
            etProgressBarForecast.ValueText = valueText;

            //////////////////////////////////////////////////////////////////////////
            if (m_GSignalManager.HighLowSignal > 0.0)
            {
                etProgressBarHighLow.StartColor = Color.Red;
                etProgressBarHighLow.EndColor = Color.Red;
                valueText = "매수 : ";
            }
            else
            {
                etProgressBarHighLow.StartColor = Color.Blue;
                etProgressBarHighLow.EndColor = Color.Blue;
                valueText = "매도 : ";
            }

            etProgressBarHighLow.Value = (int)Math.Abs(m_GSignalManager.HighLowSignal);
            valueText += etProgressBarHighLow.Value.ToString();
            valueText += "%";
            etProgressBarHighLow.ValueText = valueText;

            //////////////////////////////////////////////////////////////////////////
            if (m_GSignalManager.WorldSignal > 0.0)
            {
                etProgressBarWorld.StartColor = Color.Red;
                etProgressBarWorld.EndColor = Color.Red;
                valueText = "매수 : ";
            }
            else
            {
                etProgressBarWorld.StartColor = Color.Blue;
                etProgressBarWorld.EndColor = Color.Blue;
                valueText = "매도 : ";
            }

            etProgressBarWorld.Value = (int)Math.Abs(m_GSignalManager.WorldSignal);
            valueText += etProgressBarWorld.Value.ToString();
            valueText += "%";
            etProgressBarWorld.ValueText = valueText;

            //////////////////////////////////////////////////////////////////////////
            if (m_GSignalManager.TotalSignal > 0.0)
            {
                etProgressBarTotal.StartColor = Color.Red;
                etProgressBarTotal.EndColor = Color.Red;
                valueText = "매수 : ";
            }
            else
            {
                etProgressBarTotal.StartColor = Color.Blue;
                etProgressBarTotal.EndColor = Color.Blue;
                valueText = "매도 : ";
            }

            etProgressBarTotal.Value = (int)Math.Abs(GlobalVar.ProgressVal);
            valueText += etProgressBarTotal.Value.ToString();
            valueText += "%";
            etProgressBarTotal.ValueText = valueText;
        }
    }
}
